
package com.scs.application.modules.cert.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.service.BaseServiceImpl;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.core.utils.UserUtils;
import com.scs.application.modules.cert.entity.CertificateRepositoryHistory;
import com.scs.application.modules.cert.mapper.CertificateRepositoryHistoryMapper;
import com.scs.application.modules.cert.request.CertificateRepositoryHistoryQueryRequest;
import com.scs.application.modules.cert.service.CertificateRepositoryHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 资质历史版本 service 实现
 *
 */
@Slf4j
@Service
public class CertificateRepositoryHistoryServiceImpl extends BaseServiceImpl<CertificateRepositoryHistoryMapper, CertificateRepositoryHistory> implements CertificateRepositoryHistoryService {

    @Override
    public List<CertificateRepositoryHistory> list(CertificateRepositoryHistoryQueryRequest request) {
        if (UserUtils.isSupplier()) {
            request.setSupplierId(UserUtils.getSupplierId());
        }
        List<CertificateRepositoryHistory> list = this.list(Wrappers.<CertificateRepositoryHistory>query()
                .eq(StringUtils.isNotBlank(request.getSupplierId()), "supplier_id", request.getSupplierId())
                .eq(StringUtils.isNotBlank(request.getCertificateId()), "certificate_id", request.getCertificateId())
                .eq(StringUtils.isNotBlank(request.getTargetDescribeId()), "target_describe_id", request.getTargetDescribeId())
                .orderByDesc("gmt_modified")
        );
        return list;
    }

    @Override
    public IPage<CertificateRepositoryHistory> page(CertificateRepositoryHistoryQueryRequest request) {
        if (UserUtils.isSupplier()) {
            request.setSupplierId(UserUtils.getSupplierId());
        }
        IPage page = this.baseMapper.page(request.getPage(), request);
        return page;
    }
}
